package com.mashibing.apidriver.service;

import com.mashibing.apidriver.remote.ServiceDriverUserClient;
import com.mashibing.apidriver.remote.ServiceMapClient;
import com.mashibing.internalcommon.dto.Car;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.request.ApiDriverPointRequest;
import com.mashibing.internalcommon.request.PointDTO;
import com.mashibing.internalcommon.request.PointRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.websocket.server.ServerEndpoint;

@Service
public class PointService {
    @Autowired
    ServiceMapClient serviceMapClient;
    @Autowired
    ServiceDriverUserClient serviceDriverUserClient;

    public ResponseResult upload(ApiDriverPointRequest apiDriverPointRequest){
        //获取carid
        Long carId = apiDriverPointRequest.getCarId();
        //根据carid获取tid，trid  调用driver-user-service接口
        ResponseResult<Car> car = serviceDriverUserClient.getCarById(carId);
        String tid = car.getData().getTid();
        String trid = car.getData().getTrid();
        PointDTO[] points = apiDriverPointRequest.getPoints();
        //调用map服务获取
        PointRequest pointRequest = new PointRequest();
        pointRequest.setTid(tid);
        pointRequest.setTrid(trid);
        pointRequest.setPoints(points);


return serviceMapClient.upload(pointRequest);
    }

}
